// pages/put_forward/put_forward.js
var common = require("../../common/common.js").common;

Page({
    /**
   * 页面的初始数据
   */
    data: {
        choose: 1,
        money: 0,
        put_forward: ""
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        this.setData({
            money: options.money
        });
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {},
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {},
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {},
    choose: function() {
        var choose = this.data.choose;
        if (choose == 1) {
            choose = 2;
        } else {
            choose = 1;
        }
        this.setData({
            choose: choose
        });
    },
    all: function(e) {
        var money = e.currentTarget.dataset.money;
        this.setData({
            put_forward: money
        });
    },
    putForward: function() {
        var openid = wx.getStorageSync("user").openid;
        var that = this;
        var put_forward = that.data.put_forward;
        common.request({
            endpoint: "Apply/extractapply/extract_submit",
            method: "post",
            data: {
                openid: openid,
                price: put_forward
            },
            header: {
                "content-type": "application/json"
            },
            success: res => {
                wx.showModal({
                    title: "提示",
                    content: res.message
                });
            },
            fail: res => {
                wx.showModal({
                    title: "提示",
                    content: res.message
                });
            }
        });
    }
});